package com.amigo.online.provider.manager.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.amigo.online.common.base.controller.BaseController;
import com.amigo.online.common.core.response.Response;
import com.amigo.online.provider.manager.model.entity.AdvAreaTbl;
import com.amigo.online.provider.manager.service.AdvAreaTblService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

@RestController
@RequestMapping(value = "/advAreaTbl", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class AdvAreaTblController extends BaseController {

    @Resource
    private AdvAreaTblService advAreaTblService;

    @PostMapping(value = "/getAdvAreaTblList")
    public ResponseEntity<Response> getAdvAreaTblList(@RequestBody AdvAreaTbl aat) {
        JSONObject result = new JSONObject();
        List<AdvAreaTbl> advAreaTblList = null;
        if (aat.getPid() != null && aat.getPid() == 0) {
            Page<Object> page = PageHelper.startPage(aat.getPageNo(), 10);
            advAreaTblList = advAreaTblService.findAdvAreaTbl(aat);
            result.put("advAreaTblList", advAreaTblList);
            result.put("pagetotal", page.getTotal());
        } else {
            advAreaTblList = advAreaTblService.findAdvAreaTbl(aat);
            result.put("advAreaTblList", advAreaTblList);
        }
        return success(result);
    }

    @PostMapping(value = "/saveAdvAreaTbl")
    public ResponseEntity<Response> saveAdvAreaTbl(@RequestBody AdvAreaTbl aat) {
        return success(advAreaTblService.insertionAdvAreaTbl(aat));
    }

    @PutMapping(value = "/updateAdvAreaTbl")
    public ResponseEntity<Response> updateAdvAreaTbl(@RequestBody AdvAreaTbl aat) {
        return success(advAreaTblService.updateAdvAreaTbl(aat));
    }

    @DeleteMapping(value = "/deleteAdvAreaTbl")
    public ResponseEntity<Response> deleteAdvAreaTbl(@RequestBody AdvAreaTbl aat) {
        return success(advAreaTblService.deleteAdvAreaTbl(aat));
    }

    @PostMapping(value = "/selectAdvAreaTblInfo")
    public ResponseEntity<Response> selectAdvAreaTblInfo(@RequestBody AdvAreaTbl aat) {
        return success(advAreaTblService.selectAdvAreaTblInfo(aat));
    }

}
